public class test1_2 {
    // 力扣 11.承最多水的容器  （双指针）
    // 利用的是枚举以及单调性
    public static void main(String[] args) {
        int[] height = {1, 2, 1};
        int n = height.length;
        int left = 0;
        int right = n - 1;
        int max = 0;
        while (left != right) {
            int capacity = getCapacity(left, right, height);
            max = Math.max(capacity, max);
            if (left != right && height[left] <= height[right]) {
                left++;
            } else if (left != right && height[left] >= height[right]) {
                right--;
            }
        }
        System.out.println(max);
    }

    private static int getCapacity(int left, int right, int[] heigh) {

        return Math.min(heigh[left], heigh[right]) * Math.abs(right - left);
    }
}
